<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>回复</title>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css">
    <link rel="stylesheet" href="__PUBLIC__/admin/css/admin.css">
</head>
<body style="padding:10px;">
    <div class="layui-form">
        <input type="hidden" name="id" value="{$comment.id}">
        <div class="layui-form-item">
            <label for="" class="layui-form-label">评论内容</label>
            <div class="layui-input-block">
                {$comment.content}
            </div>
        </div>
        <div class="layui-form-item">
            <label for="" class="layui-form-label">回复内容</label>
            <div class="layui-input-block">
                <textarea id="comment-content" style="display: none;"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="" class="layui-form-label">&nbsp;</label>
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="go">立即提交</button>
            </div>
        </div>
        <notempty name="reply_list">
            <table class="layui-table">
                <colgroup>
                    <col width="60">
                    <col>
                    <col width="110">
                    <col width="80">
                </colgroup>
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>内容</th>
                        <th>时间</th>
                        <th>操作</th>
                    </tr> 
                </thead>
                <tbody>
                    <volist name="reply_list" id="vo">
                    <tr>
                        <td>{$vo.id}</td>
                        <td align="left">{$vo.content}</td>
                        <td>{$vo.str_add_time}</td>
                        <td><a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs del" data-cid="{$vo.id}">删除</a></td>
                    </tr>
                    </volist>
                </tbody>
            </table>
        </notempty>
    </div>
</body>
<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['jquery','form','layedit'],function(){
        var $ = layui.jquery,
            layedit = layui.layedit,
            form = layui.form;
        var index = layedit.build('comment-content',{
            height: 150,
            tool:['face','|','left','center','right','link','unlink']
        });
        form.on("submit(go)",function(data){
            var c = layedit.getContent(index);
            if( $.trim(c) == ''){
                layer.msg('内容不能为空！', {icon: 5,time: 1000});
                return false;
            }
            var post = {};
            post.id = data.field.id;
            post.content = c;
            $.ajax({
                url:"{:U('Admin/Comment/reply')}",
                data:post,
                type:"POST",
                dataType:'json',
                success:function(data){
                    if( data.status != 1 ){
                        layer.msg(data.msg,{icon:5});
                        return false;
                    }
                    layer.msg(data.msg,{icon:6});
                    setTimeout(function(){
                        location.reload()
                        layer.close(index);
                    },1000);
                },
                error:function(){
                    layer.msg("ERROR",{icon:5});
                    setTimeout(function(){
                        location.reload()
                        layer.close(index);
                    },1000);
                }
            });
        });
        $(".del").on('click',function(){
            var that = $(this);
            layer.confirm('是否删除?', {icon: 3, title:'提示'}, function(index){
                var post = {};
                post.id = that.data("cid");
                $.ajax({
                    url:"{:U('Admin/Comment/del_reply')}",
                    data:post,
                    type:"POST",
                    dataType:'json',
                    success:function(data){
                        if( data.status != 1 ){
                            layer.msg(data.msg,{icon:5});
                            return false;
                        }
                        layer.msg(data.msg,{icon:6});
                        setTimeout(function(){
                            location.reload()
                        },1000);
                    },
                    error:function(){
                        layer.close(index);
                        layer.msg("ERROR",{icon:5});
                        setTimeout(function(){
                            location.reload()
                        },1000);
                    }
                });
            });
        });
    });
</script>
</html>